package com.bs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bs.model.User;
import com.bs.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 说明：
 *
 * @author 琪
 * @since 2025/5/7 20:23
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<BaseMapper<User>, User> implements IUserService {

    @Override
    public boolean save(User entity) {
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        return super.save(entity);
    }

    @Override
    public boolean updateById(User entity) {
        entity.setUpdateTime(new Date());
        return super.updateById(entity);
    }

    @Override
    public User getUser(String name) {
        log.info("获取用户信息：{}", name);
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>()
                .eq("name", name)
                .last("limit 1");
        return getOne(queryWrapper);
    }
}